package com.lb.jwitter.action;


import java.text.DateFormat; 
import java.text.SimpleDateFormat; 
import java.util.ArrayList; 
import java.util.List; 
import org.springframework.beans.factory.annotation.Autowired;
import com.lb.jwitter.util.ApplicationContextProvider; 
import org.springframework.context.ApplicationContext;
import java.util.Map; 
import org.springframework.test.context.ContextConfiguration; 
import com.lb.jwitter.service.TblQuyenChiTietService; 
import com.lb.jwitter.service.TblTaiKhoan; 
import com.opensymphony.xwork2.ActionContext; 
import java.util.Date; 
import java.util.GregorianCalendar; 
import javax.xml.datatype.DatatypeFactory; 
import javax.xml.datatype.XMLGregorianCalendar; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import com.lb.jwitter.service.ConditionReport; 
import com.lb.jwitter.util.Message; 
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.TblQLDTTXAChuongTrinhHocChiTiet;
import com.lb.jwitter.service.TblQLDTTXAChuongTrinhHocChiTietService;
import com.lb.jwitter.service.TblQLDTTXAChuongTrinhHoc;
import com.lb.jwitter.service.TblQLDTTXAChuongTrinhHocService;

import com.lb.jwitter.service.TblQLDTTXAHocKy;
import com.lb.jwitter.service.TblQLDTTXAHocKyService;

import com.lb.jwitter.service.TblQLDTTXAMonHoc;
import com.lb.jwitter.service.TblQLDTTXAMonHocService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblQLDTTXAChuongTrinhHoctblQLDTTXAChuongTrinhHocChiTietInsertAction{
    private Message msg; 
    public Message getMsg() { return msg; }

    private Long id; 
    public void setId(Long id) {
       this.id = id;
 }

    private int chuongTrinhHocId; 
    public void setChuongTrinhHocId(int chuongTrinhHocId) {
       this.chuongTrinhHocId = chuongTrinhHocId;
 }

    public int getChuongTrinhHocId() {
       return chuongTrinhHocId;
 }

    private TblQLDTTXAChuongTrinhHocService tblQLDTTXAChuongTrinhHocService; 

    private int hocKyId; 
    public void setHocKyId(int hocKyId) {
       this.hocKyId = hocKyId;
 }

    public int getHocKyId() {
       return hocKyId;
 }

    private TblQLDTTXAHocKyService tblQLDTTXAHocKyService; 

    private int monHocId; 
    public void setMonHocId(int monHocId) {
       this.monHocId = monHocId;
 }

    public int getMonHocId() {
       return monHocId;
 }

    private TblQLDTTXAMonHocService tblQLDTTXAMonHocService; 

    private TblQLDTTXAChuongTrinhHocChiTiet tblQLDTTXAChuongTrinhHocChiTiet; 
    public TblQLDTTXAChuongTrinhHocChiTiet  getTblQLDTTXAChuongTrinhHocChiTiet() {
        return tblQLDTTXAChuongTrinhHocChiTiet;
 }

    private TblQLDTTXAChuongTrinhHocChiTietService tblQLDTTXAChuongTrinhHocChiTietService; 

	private int preInsert(Message msg, TblQLDTTXAChuongTrinhHocChiTiet obj ){ 
        msg.setPreMessage_b(true); 
        msg.setPreMessage_s("success"); 
        return 1; 
    } 
	private int postInsert(Message msg, TblQLDTTXAChuongTrinhHocChiTiet obj ){ 
        msg.setPostMessage_b(true); 
        msg.setPostMessage_s("success"); 
        return 1; 
    } 
  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
    public String execute() throws Exception 
   { 
    try{ 
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_ChuongTrinhHoc_ChiTiet", "them")){ 
        return "noprivilege"; 
 } 
        tblQLDTTXAChuongTrinhHocChiTietService = (TblQLDTTXAChuongTrinhHocChiTietService) context.getBean("tbl_QLDTTXA_ChuongTrinhHoc_ChiTietClient"); 
        tblQLDTTXAChuongTrinhHocService = (TblQLDTTXAChuongTrinhHocService) context.getBean("tbl_QLDTTXA_ChuongTrinhHocClient"); 

        tblQLDTTXAHocKyService = (TblQLDTTXAHocKyService) context.getBean("tbl_QLDTTXA_HocKyClient"); 

        tblQLDTTXAMonHocService = (TblQLDTTXAMonHocService) context.getBean("tbl_QLDTTXA_MonHocClient"); 

        msg = new Message(); 
        tblQLDTTXAChuongTrinhHocChiTiet = new TblQLDTTXAChuongTrinhHocChiTiet(); 
        tblQLDTTXAChuongTrinhHocChiTiet.setChuongTrinhHocId(tblQLDTTXAChuongTrinhHocService.gettblQLDTTXAChuongTrinhHoc(new Long(chuongTrinhHocId))); 
        tblQLDTTXAChuongTrinhHocChiTiet.setHocKyId(tblQLDTTXAHocKyService.gettblQLDTTXAHocKy(new Long(hocKyId))); 
        tblQLDTTXAChuongTrinhHocChiTiet.setMonHocId(tblQLDTTXAMonHocService.gettblQLDTTXAMonHoc(new Long(monHocId))); 
        preInsert(msg,tblQLDTTXAChuongTrinhHocChiTiet); 
       if (msg.isPreMessage_b()) 
       { 
           id = tblQLDTTXAChuongTrinhHocChiTietService.createtblQLDTTXAChuongTrinhHocChiTiet(tblQLDTTXAChuongTrinhHocChiTiet); 
           postInsert(msg, tblQLDTTXAChuongTrinhHocChiTiet); 
           if (msg.isPostMessage_b() == false) 
           { 
               return Action.ERROR; 
           } 
       }else{ 
           return Action.ERROR; 
       } 
        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
         System.out.println("Loi Insert tbl_QLDTTXA_ChuongTrinhHoc_ChiTiet Action"); 
         e.printStackTrace(); 
         return Action.ERROR; 
 } 
 }

	public Long getId() {
		return id;
	} 
 } 
 
